import {
    list_servs
} from '../actions/servs';

import {
    set_branches_servsid
} from '../actions/deploy';

function servs (state = {}, action) {
    let servs = {};
    switch (action.type) {
        case set_branches_servsid:
            servs = state;
            servs[action.servsid].list = action.list;
            return Object.assign({}, state, servs);
        case list_servs:
            for(let i = 0; i < action.list.length; i++){
                servs[action.list[i].serviceId] = {};
                servs[action.list[i].serviceId].name = action.list[i].serviceName;
                servs[action.list[i].serviceId].lineDb = action.list[i].lineDb;
                servs[action.list[i].serviceId].targetBranch = action.list[i].targetBranch;
                servs[action.list[i].serviceId].list = [];
            }
            return Object.assign({}, state, servs);
        default:
            return state;    
    }
}

export default servs;